package top.yuechenc.manage.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;
import top.yuechenc.manage.entity.SpCategory;
import top.yuechenc.manage.entity.SpCategoryDto;
import top.yuechenc.manage.mapper.SpCategoryMapper;
import top.yuechenc.manage.service.CategoryService;

import java.util.List;

/**
 * @author wangzhiwei
 */
@Service
public class CategoryServiceImpl implements CategoryService {
    @Autowired
    private SpCategoryMapper spCategoryMapper;

    @Override
    public PageInfo<SpCategory> findListByParam(SpCategory spCategory, int pageNum, int pageSize) {

        Example example = new Example(SpCategory.class);
        //Example.Criteria criteria=example.createCriteria();

        PageHelper.startPage(pageNum, pageSize);
        List<SpCategory> spCategoryList = spCategoryMapper.selectByExample(example);
        return new PageInfo<>(spCategoryList);
    }

    @Override
    public List<SpCategoryDto> getByCatPid(String catPid) {
        return spCategoryMapper.getByCatPid(catPid);
    }

    @Override
    public PageInfo<SpCategoryDto> getByCatPid(String catPid, int pageNum, int pageSize) {
        Example example=new Example(SpCategory.class);
        PageHelper.startPage(pageNum, pageSize);
        List<SpCategoryDto> spCategoryDtos=spCategoryMapper.getByCatPid(catPid);
        return new PageInfo<>(spCategoryDtos);
    }

    @Override
    public void addCate(SpCategory spCategory) {
        spCategoryMapper.insertSelective(spCategory);
    }

    @Override
    public SpCategory findById(String catId) {
        return spCategoryMapper.selectByPrimaryKey(catId);
    }

    @Override
    public void updById(SpCategory spCategory) {
        spCategoryMapper.updateByPrimaryKeySelective(spCategory);
    }

    @Override
    public void delById(String catId) {
        spCategoryMapper.deleteByPrimaryKey(catId);
    }
}
